//
//  main.cpp
//  KV_BinarySearchTree
//
//  Created by 卜绎皓 on 2022/11/7.
//

#include"_BinarySearchTree.hpp"

void TestBSTree1()
{
    KEY_VALUE::BSTree<string, string> dict;
    dict.Insert("sort", "排序");
    dict.Insert("insert", "插入");
    dict.Insert("tree", "树");
    dict.Insert("left", "左边");
    dict.Insert("right", "右边");
    //...
    string str;
    while(cin >> str)
    {
        if(str == "Q")
        {
            break;
        }
        else
        {
            auto ret = dict.Find(str);
            if(ret == nullptr)
            {
                cout << "拼写错误,请检查你的单词" << endl;
            }
            else
            {
                cout << ret->_key <<  "->" << ret->_value << endl;
            }
        }
    }
}
void TestBSTree2()
{
    string str[] = {"sort", "sort", "tree", "insert", "sort", "tree", "sort", "test", "sort" };
    KEY_VALUE::BSTree<string, int> countTree;
    for(auto& e : str)
    {
        auto ret = countTree.Find(e);
        if(ret == nullptr)
        {
            countTree.Insert(e, 1);//第一次出现
        }
        else
        {
            ret->_value++;//非第一次出现
        }
    }
    countTree.InOrder();
}
int main()
{
    TestBSTree1();
    TestBSTree2();
    
    return 0;
}
